{% extends "base.html" %}
 
{% block title %}
{{ user.userName }}
{% endblock title %}

{% block js %}
<script type="text/javascript">
    $(function () {
        $("#saveButton").click(function () {
            var json_obj = {
                id: $("#id").val(),
                userCode: $("#userCode").val(),
                userName: $("#userName").val(),
                password: $("#password").val(),
                sex: $("#sex").val(),
                email: $("#email").val(),
                age: $("#age").val()
            };
            $.ajax({
                type: "POST",
                url: $("#userForm").attr("action"),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                data: JSON.stringify(json_obj),
                success: function (data) {
                    if (data.code == 200) {
                        alert(data.message)
                    } else {
                        alert('保存失败，请稍后重试')
                    }
                }
            });
        })
    })
</script>
{% endblock js %}
 
{% block content %}
<form id="userForm" action="/user/save" method="post">
    <table>
        <thead>
            <tr>
                <td>用户编号</td>
                <td>用户姓名</td>
                <td>密码</td>
                <td>性别</td>
                <td>邮箱</td>
                <td>年龄</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input type="text" id="userCode" name="userCode" value="{{ user.userCode }}"></td>
                <td><input type="text" id="userName" name="userName" value="{{ user.userName }}"></td>
                <td><input type="password" id="password" name="password" value="{{ user.password }}"></td>
                <td><input type="text" id="sex" name="sex" value="{{ user.sex }}"></td>
                <td><input type="text" id="email" name="email" value="{{ user.email }}"></td>
                <td><input type="text" id="age" name="age" value="{{ user.age }}"></td>
                <td>
                    {% csrf_token %}
                    <input type="hidden" id="id" name="id" value="{{ user.id }}">
                    <input type="button" id="saveButton" value="保存">
                </td>
            </tr>
        </tbody>
    </table>
</form>
{% endblock content %}
